package com.sunny.springboot2.controller;

import com.sunny.springboot2.core.annotation.Limit;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 限流测试Controller
 * @author sunny
 * @date 2018/11/28
 */
@RestController
@RequestMapping("/noPer/limiter")
public class LimiterController {

    private static final AtomicInteger ATOMIC_INTEGER = new AtomicInteger();

    @GetMapping("/limit")
    @Limit(key = "server", period = 100, count = 10)
    public int testLimiter() {
        //意味100s内最多允许访问10次
        return ATOMIC_INTEGER.incrementAndGet();
    }
}
